home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / FrameProxy.cpp < prev    next >
Encoding:
Text File  |  1995-12-11  |  36.4 KB  |  1,387 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FrameProxy.cpp
  3.  
  4.     Contains:    CEmbeddedFrameProxy class Implementation
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. #ifndef _FRAMEPROXY_
  18. #include "FrameProxy.h"
  19. #endif
  20.  
  21. #ifndef _SHAPES_
  22. #include "Shapes.h"
  23. #endif
  24.  
  25.  
  26. // -- DrawEditor Includes --
  27.  
  28. #ifndef _COMMAND_
  29. #include "Command.h"
  30. #endif
  31.  
  32. #ifndef _DRAWEDITORGLOBALS_
  33. #include "DrawEditorGlobals.h"
  34. #endif
  35.  
  36. #ifndef _DRAWEDITORCONSTANTS_
  37. #include "DrawEditorConstants.h"
  38. #endif
  39.  
  40. #ifndef _DRAWEDITOR_
  41. #include "DrawEditor.h"
  42. #endif
  43.  
  44. #ifndef _DRAWEDITORUTILS_
  45. #include "DrawEditorUtils.h"
  46. #endif
  47.  
  48. // -- OpenDoc Includes --
  49.  
  50. #ifndef SOM_ODFrameFacetIterator_xh
  51. #include <FrFaItr.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODDraft_xh
  55. #include <Draft.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODTransform_xh
  59. #include <Trnsform.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODFrame_xh
  63. #include <Frame.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODFacet_xh
  67. #include <Facet.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODFacetIterator_xh
  71. #include <FacetItr.xh>
  72. #endif
  73.  
  74. // -- OpenDoc Utilities --
  75.  
  76. #ifndef _ODUTILS_
  77. #include "ODUtils.h"
  78. #endif
  79.  
  80. #ifndef _ODDEBUG_
  81. #include "ODDebug.h"
  82. #endif
  83.  
  84. #ifndef _STORUTIL_
  85. #include <StorUtil.h>
  86. #endif
  87.  
  88. #ifndef _ORDCOLL_
  89. #include "OrdColl.h"
  90. #endif
  91.  
  92. //=============================================================================
  93. // Notes:
  94. // For the embedded frame proxies, need some code to disambiguate frame 
  95. // groups and sequences upon internalization of embedded frames. For example,
  96. // when the 3rd frame in a sequence is cut/copied and pasted into another document
  97. // which may or may not have frames in the ( pasted ) frames group/sequence.
  98. //=============================================================================
  99.  
  100.  
  101. //=============================================================================
  102. // CFrameProxy
  103. //=============================================================================
  104. //------------------------------------------------------------------------------
  105. // Method:        CFrameProxy Constructor
  106. //
  107. // Description:    Put the CFrameProxy into a safely disposable state.
  108. //
  109. //------------------------------------------------------------------------------
  110.  
  111. CFrameProxy::CFrameProxy()
  112. {
  113.     fIsInited = kODFalse;
  114.     
  115.     fFrame = kODNULL;
  116. }
  117.  
  118.  
  119. //------------------------------------------------------------------------------
  120. // Method:        InitializeFrameProxy
  121. //
  122. // Description:    Put the CFrameProxy into a usable state.
  123. //
  124. //------------------------------------------------------------------------------
  125.  
  126. void CFrameProxy::InitializeFrameProxy( Environment* ev, 
  127.                                     DrawEditor* editor, 
  128.                                     ODID frameID, 
  129.                                     ODFrame* frame )
  130. {
  131.     ASSERT(editor != NULL, kODErrInvalidParameter);
  132.     
  133.     fDrawEditor = editor;
  134.     
  135.     fFrame = kODNULL;
  136.     
  137.     // We MUST have either a frame ID or a frame pointer
  138.     if (frame != kODNULL)
  139.     {
  140.         fFrameID = frame->GetID(ev);
  141.         fFrame = frame;
  142.     }
  143.     else
  144.     {
  145.         fFrameID = frameID;
  146.     }
  147.  
  148.     fIsInited = kODTrue;
  149. }
  150.  
  151.  
  152. //------------------------------------------------------------------------------
  153. // Method:        CFrameProxy Destructor
  154. //
  155. // Description:    
  156. //
  157. //------------------------------------------------------------------------------
  158.  
  159. CFrameProxy::~CFrameProxy()
  160. {
  161. }
  162.  
  163. //------------------------------------------------------------------------------
  164. // Method:        GetFrameID
  165. //
  166. // Description:    
  167. //
  168. //------------------------------------------------------------------------------
  169. ODID CFrameProxy::GetFrameID() const
  170. {
  171.     return fFrameID;
  172. }
  173. //------------------------------------------------------------------------------
  174. // Method:        SetFrame
  175. //
  176. // Description:    
  177. //
  178. //------------------------------------------------------------------------------
  179. void CFrameProxy::SetFrame(ODFrame* frame)
  180. {
  181.     Environment* ev = somGetGlobalEnvironment();
  182.     
  183.     fFrame = frame;
  184.     if (fFrame)
  185.     {
  186.         ODAcquireObject(ev, fFrame);
  187.         fFrameID = frame->GetID(ev);
  188.     }
  189. }
  190.  
  191.  
  192. //------------------------------------------------------------------------------
  193. // Method:        GetFrame
  194. //
  195. // Description:    GetFrame attempts to return a frame which is in a usable state.
  196. // It does this by either returning the frame reference it has ( if non null ) 
  197. // or, internalizing a frame from the given frame ID ( given in the constructor )
  198. //------------------------------------------------------------------------------
  199. ODFrame* CFrameProxy::GetFrame(Environment* ev)
  200. {
  201.     if (fFrame)
  202.         return fFrame;
  203.         
  204.     if (fFrameID == kODNULLID)
  205.         return kODNULL;
  206.     
  207.     // We have an ID, acquire it from the draft
  208.     ODDraft* draft = fDrawEditor->GetDraft(ev);
  209.     fFrame = draft->AcquireFrame(ev, fFrameID);
  210.     
  211.     // Ensure the frame is not in limbo
  212.     fFrame->SetInLimbo(ev, kODFalse);
  213.     
  214.     return fFrame;
  215. }
  216.  
  217. //------------------------------------------------------------------------------
  218. // Method:        IsFrameInMemory
  219. //
  220. // Description:    
  221. //
  222. //------------------------------------------------------------------------------
  223. ODBoolean CFrameProxy::IsFrameInMemory() const
  224. {
  225.     return fFrame != NULL;
  226. }
  227.  
  228.  
  229. //=============================================================================
  230. // CDisplayFrameProxy
  231. //=============================================================================
  232.  
  233. //------------------------------------------------------------------------------
  234. // Method:        CDisplayFrameProxy Constructor
  235. //
  236. // Description:    
  237. //
  238. //------------------------------------------------------------------------------
  239.  
  240. CDisplayFrameProxy::CDisplayFrameProxy()
  241. {
  242. }
  243.  
  244.  
  245. //------------------------------------------------------------------------------
  246. // Method:        InitializeDisplayFrameProxy
  247. //
  248. // Description:    Put the display frame proxy into a usable state.
  249. //
  250. //------------------------------------------------------------------------------
  251.  
  252. void CDisplayFrameProxy::InitializeDisplayFrameProxy( Environment* ev, 
  253.                                                     DrawEditor* editor, 
  254.                                                     ODID frameID, 
  255.                                                     ODFrame* frame )
  256. {
  257.     TRY
  258.         // Sets base fields, and marks as initialized
  259.         CFrameProxy::InitializeFrameProxy(ev, editor, frameID, frame);
  260.     
  261.         if (frame)
  262.             ODAcquireObject(ev, frame);
  263.     CATCH_ALL
  264.     ENDTRY
  265.     
  266. }
  267.  
  268. //------------------------------------------------------------------------------
  269. // Method:        CDisplayFrameProxy Destructor
  270. //
  271. // Description:    
  272. //
  273. //------------------------------------------------------------------------------
  274.  
  275. CDisplayFrameProxy::~CDisplayFrameProxy()
  276. {
  277.     Environment* ev = somGetGlobalEnvironment();
  278.     
  279.     if (this->IsFrameInMemory())
  280.     {
  281.         ODSafeReleaseObject(fFrame);
  282.     }
  283.     
  284. }
  285.  
  286. //------------------------------------------------------------------------------
  287. // Method:        Read
  288. //
  289. // Description:
  290. //
  291. //------------------------------------------------------------------------------
  292. ODBoolean CDisplayFrameProxy::Read(Environment* ev, ODStorageUnit* storage, 
  293.                                             CCloneInfo* cloneInfo)
  294. {
  295.     TRY
  296.         ODStorageUnitRef aSURef;
  297.                 
  298.         StorageUnitGetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
  299.         
  300.         if (!storage->IsValidStorageUnitRef(ev, aSURef))
  301.             return kODFalse;
  302.         
  303.         ODStorageUnitID fromFrameID = storage->GetIDFromStorageUnitRef(ev, aSURef);
  304.     
  305.         if (cloneInfo != NULL)
  306.         {
  307.             ODDraft* tDraft = storage->GetDraft(ev);
  308.             
  309.             // ----- We are cloning -----
  310.             fFrameID = cloneInfo->fFromDraft->Clone(ev, cloneInfo->fKey, fromFrameID, kODNULLID, kODNULLID);
  311.         }
  312.         else
  313.         {
  314.             // ----- We are just reading -----
  315.             fFrameID = fromFrameID;
  316.         }
  317.     
  318.     CATCH_ALL
  319.         return kODFalse;
  320.     ENDTRY
  321.         
  322.     return kODTrue;
  323. }                                                
  324.  
  325.  
  326. //------------------------------------------------------------------------------
  327. // Method:        Write
  328. //
  329. // Description:    
  330. //
  331. //------------------------------------------------------------------------------
  332. void CDisplayFrameProxy::Write(Environment* ev, ODStorageUnit* storage, 
  333.                                         CCloneInfo* cloneInfo)
  334. {
  335.     ODStorageUnitRef aSURef;
  336.     
  337.     if (cloneInfo != NULL)
  338.     {
  339.         ODStorageUnitID frameID;
  340.         ODID scopeFrameID = kODNULLID;
  341.         
  342.         // Scope frame may be null as in the case where clone into is passed a null frame.
  343.         if (cloneInfo->fScopeFrame)
  344.         {
  345.             scopeFrameID = cloneInfo->fScopeFrame->GetID(ev);
  346.         }
  347.         
  348.         frameID = cloneInfo->fFromDraft->WeakClone(ev, cloneInfo->fKey, 
  349.                                 fFrameID, kODNULLID, scopeFrameID);
  350.                   
  351.          storage->GetWeakStorageUnitRef(ev, frameID, aSURef);
  352.     }
  353.     else
  354.     {
  355.         // Its not a clone
  356.          storage->GetWeakStorageUnitRef(ev, fFrameID, aSURef);
  357.     }
  358.     
  359.     // ----- Write out the embedded frame reference -----
  360.      StorageUnitSetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
  361. }
  362.  
  363. //=============================================================================
  364. // CEmbeddedFrameProxy
  365. //=============================================================================
  366.  
  367.  
  368. //------------------------------------------------------------------------------
  369. // Method:        CEmbeddedFrameProxy Constructor
  370. //
  371. // Description:    Put the proxy into a safely disposable state.
  372. //
  373. //------------------------------------------------------------------------------
  374.  
  375. CEmbeddedFrameProxy::CEmbeddedFrameProxy()
  376. {
  377.     fEmbeddingShape = kODNULL;
  378.     fContainingFrameID = kODNULLID;
  379.     fSavedFrameSequence = 0L;
  380.     fPart = kODNULL;
  381.     fPresentation = kODNullTypeToken;
  382.     fViewType = kODNullTypeToken;
  383.     fAttached = kODFalse;
  384. }
  385.  
  386.  
  387. //------------------------------------------------------------------------------
  388. // Method:        InitializeEmbeddedFrameProxy
  389. //
  390. // Description:    Put the proxy into a usable state.
  391. //
  392. // Use this constructor when the part is known but there is no ODFrame or 
  393. // ODFrameID
  394. //------------------------------------------------------------------------------
  395.  
  396. void CEmbeddedFrameProxy::InitializeEmbeddedFrameProxy( Environment* ev, 
  397.                             DrawEditor* editor, 
  398.                             CEmbeddingShape* shape, 
  399.                             ODFrame* containingFrame, 
  400.                             ODPart* part,
  401.                             ODTypeToken viewType,
  402.                             ODTypeToken presentation) 
  403. {
  404.     ASSERT(editor != NULL, kODErrInvalidParameter);
  405.     ASSERT(shape != NULL, kODErrInvalidParameter);
  406.     ASSERT(part != NULL, kODErrInvalidParameter);
  407.     
  408.     TRY
  409.         fContainingFrameID = containingFrame->GetID(ev);
  410.         
  411.         // OD Bug see FrameProxy.h
  412.         // fPartID = part->GetID(ev);
  413.         ODAcquireObject(ev, part);
  414.         fPart = part;
  415.         
  416.         fPresentation = presentation;
  417.         fViewType = viewType;
  418.         
  419.         fEmbeddingShape = shape;
  420.         
  421.         // Sets base fields, and marks as initialized
  422.         CFrameProxy::InitializeFrameProxy(ev, editor, kODNULLID, kODNULL);
  423.         
  424.     CATCH_ALL
  425.     ENDTRY
  426. }
  427.  
  428.  
  429. //------------------------------------------------------------------------------
  430. // Method:        InitializeEmbeddedFrameProxy
  431. //
  432. // Description: Put the proxy into a usable state.
  433. //
  434. // Use this constructor for reading in a FrameProxy
  435. //------------------------------------------------------------------------------
  436.  
  437. void CEmbeddedFrameProxy::InitializeEmbeddedFrameProxy( Environment* ev, 
  438.                             DrawEditor* editor, 
  439.                             CEmbeddingShape* shape)
  440. {
  441.     ASSERT(editor != NULL, kODErrInvalidParameter);
  442.     ASSERT(shape != NULL, kODErrInvalidParameter);
  443.     
  444.     TRY
  445.         fContainingFrameID = kODNULLID;
  446.         
  447.         // OD Bug see FrameProxy.h
  448.         // fPartID = kODNULLID;
  449.         fPart = kODNULL;
  450.         
  451.         fEmbeddingShape = shape;
  452.         
  453.         // Sets base fields, and marks as initialized
  454.         CFrameProxy::InitializeFrameProxy(ev, editor, kODNULLID, kODNULL);
  455.     CATCH_ALL
  456.     ENDTRY
  457. }
  458.  
  459.  
  460. //------------------------------------------------------------------------------
  461. // Method:        InitializeEmbeddedFrameProxy
  462. //
  463. // Description:    Put the proxy into a usable state.    
  464. //
  465. //------------------------------------------------------------------------------
  466.  
  467. void CEmbeddedFrameProxy::InitializeEmbeddedFrameProxy(    Environment* ev, 
  468.                             DrawEditor* editor, 
  469.                             CEmbeddingShape* shape, 
  470.                             ODID frameID, 
  471.                             ODFrame* containingFrame ) 
  472. {
  473.     ASSERT(editor != NULL, kODErrInvalidParameter);
  474.     ASSERT(shape != NULL, kODErrInvalidParameter);
  475.     ASSERT(containingFrame != NULL, kODErrInvalidParameter);
  476.     ASSERT(frameID != kODNULLID, kODErrInvalidParameter);
  477.  
  478.     TRY
  479.         fContainingFrameID = containingFrame->GetID(ev);
  480.     
  481.         fEmbeddingShape = shape;
  482.         
  483.         // Sets base fields, and marks as initialized
  484.         CFrameProxy::InitializeFrameProxy(ev, editor, frameID, kODNULL);
  485.     CATCH_ALL    
  486.     ENDTRY
  487. }
  488.  
  489.  
  490. //------------------------------------------------------------------------------
  491. // Method:        CEmbeddedFrameProxy Destructor
  492. //
  493. // Description:    
  494. //
  495. //------------------------------------------------------------------------------
  496.  
  497. CEmbeddedFrameProxy::~CEmbeddedFrameProxy()
  498. {
  499.     // The following code should only get execute in the case that a frame
  500.     // was removed from the document temporarily and the remove was never 
  501.     // commited.
  502.     Environment* ev = somGetGlobalEnvironment();
  503.     
  504.     if (this->IsFrameInMemory())
  505.     {
  506.         // Get frame without attaching it
  507.         ODFrame* tFrame = CFrameProxy::GetFrame(ev);
  508.         tFrame->Remove(ev);
  509.         
  510.         // The frame is no longer in memory, 
  511.         // protect the base class from release too many times
  512.         this->SetFrame(kODNULL);
  513.     }
  514.     
  515.     ODSafeReleaseObject(fPart);
  516. }
  517.  
  518. //------------------------------------------------------------------------------
  519. // Method:        IsOrphaned
  520. //
  521. // Description:    
  522. //
  523. //------------------------------------------------------------------------------
  524. ODBoolean CEmbeddedFrameProxy::IsOrphaned() const
  525. {
  526.     return fContainingFrameID==kODNULLID;
  527. }
  528.  
  529. //------------------------------------------------------------------------------
  530. // Method:        SetContainingFrame
  531. //
  532. // Description:    Set the containing frame ID for this frame proxy. Do not call
  533. // this if this proxy is already attached.
  534. //
  535. //------------------------------------------------------------------------------
  536. void CEmbeddedFrameProxy::SetContainingFrame(Environment* ev, ODID id)
  537. {    
  538.     ASSERT(!IsAttached(ev), kODErrInvalidParameter);
  539.  
  540.     fContainingFrameID = id;
  541. }
  542.         
  543.  
  544. //------------------------------------------------------------------------------
  545. // Method:        GetContainingFrameID
  546. //
  547. // Description:    
  548. //
  549. //------------------------------------------------------------------------------
  550. ODID CEmbeddedFrameProxy::GetContainingFrameID(Environment* ev) const
  551. {
  552.     return fContainingFrameID;
  553. }
  554.  
  555.  
  556. //------------------------------------------------------------------------------
  557. // Method:        GetFrame
  558. //
  559. // Description:    GetFrame attempts to return a frame which is in a usable state.
  560. // If only an ID exists in the proxy, it will try to acquire the frame. If there 
  561. // isn't an ID, it will create an embedded frame ( if it has a part reference ).
  562. // If the frame already exists, but is unattached, it will attach it. This could 
  563. // cause problems if you call GetFrame after you have detached the proxy and are 
  564. // planning to permanently remove it, for example.
  565. //------------------------------------------------------------------------------
  566. ODFrame* CEmbeddedFrameProxy::GetFrame(Environment* ev)
  567. {
  568.     ODFrame* tFrame;
  569.     
  570.     TRY
  571.     if (this->IsFrameInMemory())
  572.     {
  573.         // We have a valid frame reference, get it into our temp
  574.         tFrame = CFrameProxy::GetFrame(ev);
  575.         
  576.         // but it may not be attached
  577.         // ( Because it was removed temporarily like from a cut or undone paste )
  578.         // If not, then make it so
  579.         if (!this->IsAttached(ev))
  580.         {
  581.             this->Attach(ev);
  582.         }
  583.     }
  584.     else
  585.     {
  586.         tFrame = CFrameProxy::GetFrame(ev);
  587.         // InternalizingFrame $$$$$ DCS
  588.         if (tFrame != kODNULL)
  589.         {
  590.             
  591.             // Add frame to list of embedded frames
  592.             fDrawEditor->GetEmbeddedFrames()->AddLast(tFrame);
  593.             
  594.             // If being internalized by ID we need to be attached
  595.             this->Attach(ev);
  596.         }
  597.         else
  598.         if (this->GetFrameID()==kODNULLID)
  599.         {
  600.             // We don't have a frame ID, embed a new frame
  601.             // Create an embedded frame
  602.             ODFrame* containingFrame = this->AcquireContainingFrame(ev);
  603.             
  604.             // Make sure we have a valid part ref
  605.             THROW_IF_NULL(fPart);
  606.                 
  607.             // Frame shapes are zero based, make the region zero based,
  608.             // so make a zero based region based on the shapes bounds.
  609.             ODRgnHandle tempShapeRegion = NewRgn();
  610.             THROW_IF_NULL(tempShapeRegion);
  611.             Rect tRect;
  612.             fEmbeddingShape->GetBoundingBox(&tRect);
  613.             SetRectRgn(tempShapeRegion, 0, 0, tRect.right - tRect.left, 
  614.                                                 tRect.bottom - tRect.top);
  615.             
  616.             ODTypeToken presentation = fPresentation ? fPresentation : gGlobals->fUndefinedPresentation;
  617.             ODTypeToken viewType = fViewType ? fViewType : gGlobals->fFrameView;
  618.             
  619.             ODShape* newShape = containingFrame->CreateShape(ev);
  620.             THROW_IF_NULL(newShape);
  621.             newShape->SetQDRegion(ev, tempShapeRegion);
  622.             
  623.             tFrame = fDrawEditor->GetDraft(ev)->CreateFrame(ev, 
  624.                                                     kODFrameObject, 
  625.                                                     containingFrame, 
  626.                                                     newShape, 
  627.                                                     kODNULL, // BiasCanvas (ODCanvas*)
  628.                                                     fPart, 
  629.                                                     viewType, 
  630.                                                     presentation,
  631.                                                     kODFalse, // IsSubframe is FALSE
  632.                                                     kODFalse); //isOverlaid
  633.             
  634.             // Save the internalized frame reference immediately
  635.             // Otherwise attaching later will cause stack overflow.
  636.             fFrame = tFrame;
  637.             
  638.             // We assume that if we are here that this frame is not part of any group
  639.             // and is the first in its sequence
  640.             tFrame->SetFrameGroup(ev, 0L);
  641.             tFrame->ChangeSequenceNumber(ev, 0L);
  642.             
  643.             // Assign our local frame ID field as well
  644.             fFrameID = tFrame->GetID(ev);
  645.             
  646.             // Atach this frame, Create facets for it
  647.             this->Attach(ev);    
  648.             
  649.             // Release acquired containing frame, shape, part
  650.             ODReleaseObject(ev, newShape);
  651.             ODReleaseObject(ev, containingFrame);
  652.             
  653.             // Add frame to list of embedded frames
  654.             fDrawEditor->GetEmbeddedFrames()->AddLast(tFrame);
  655.         }
  656.         else
  657.         {
  658.             // We have a frame ID, yet we could not internalize the frame
  659.             // Something must be seriously wrong
  660.             THROW_IF_NULL(tFrame);
  661.         }
  662.         
  663.     }
  664.     CATCH_ALL
  665.         DebugStr("\p Trouble getting the frame!");
  666.     ENDTRY
  667.  
  668.     return tFrame;
  669. }
  670.  
  671.  
  672. //------------------------------------------------------------------------------
  673. // Method:        AcquireContainingFrame
  674. //
  675. // Description:    You MUST release the frame that is returned by this method.
  676. //
  677. //------------------------------------------------------------------------------
  678. ODFrame* CEmbeddedFrameProxy::AcquireContainingFrame(Environment* ev)
  679. {            
  680.             
  681.     // If we haven't filled in the containing frame field, do it now
  682.     if (fContainingFrameID==kODNULLID)
  683.     {
  684.         ODFrame* frame = this->GetFrame(ev);
  685.         if (frame)
  686.         {
  687.             ODFrame* tFrame = frame->AcquireContainingFrame(ev);
  688.             fContainingFrameID = tFrame->GetID(ev);
  689.             
  690.             // Return tFrame as containing frame
  691.             return tFrame;
  692.         }
  693.         else
  694.             DebugStr("\p Calling  AcquireContainingFrame too early!");
  695.     }
  696.     
  697.     ODDraft* draft =  fDrawEditor->GetDraft(ev);
  698.     ODFrame* containingFrame = draft->AcquireFrame(ev, fContainingFrameID);
  699.     THROW_IF_NULL(containingFrame);
  700.     
  701.     return containingFrame;
  702. }
  703.  
  704.  
  705. //------------------------------------------------------------------------------
  706. // Method:        Read
  707. //
  708. // Description:    
  709. //
  710. //------------------------------------------------------------------------------
  711. ODBoolean CEmbeddedFrameProxy::Read(Environment* ev, ODStorageUnit* storage, 
  712.                                                 CCloneInfo* cloneInfo)
  713. {
  714.     TRY
  715.         ODStorageUnitRef aSURef;
  716.                 
  717.         StorageUnitGetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
  718.         
  719.         if (!storage->IsValidStorageUnitRef(ev, aSURef))
  720.             return kODFalse;
  721.         
  722.         ODStorageUnitID fromFrameID = storage->GetIDFromStorageUnitRef(ev, aSURef);
  723.     
  724.         if (cloneInfo != NULL)
  725.         {
  726.             ODDraft* tDraft = storage->GetDraft(ev);
  727.             
  728.             // ----- We are cloning -----
  729.             fFrameID = cloneInfo->fFromDraft->Clone(ev, cloneInfo->fKey, fromFrameID, kODNULLID, kODNULLID);
  730.             fContainingFrameID = cloneInfo->fScopeFrame->GetID(ev);
  731.         }
  732.         else
  733.         {
  734.             // ----- We are just reading -----
  735.             fFrameID = fromFrameID;
  736.         }
  737.     
  738.     CATCH_ALL
  739.         return kODFalse;
  740.     ENDTRY
  741.         
  742.     return kODTrue;
  743. }                                                
  744.  
  745.  
  746. //------------------------------------------------------------------------------
  747. // Method:        Write
  748. //
  749. // Description:    
  750. //
  751. //------------------------------------------------------------------------------
  752. void CEmbeddedFrameProxy::Write(Environment* ev, ODStorageUnit* storage, 
  753.                                                 CCloneInfo* cloneInfo)
  754. {
  755.     ODStorageUnitRef aSURef;
  756.     
  757.     if (cloneInfo != NULL)
  758.     {
  759.         // Assert that we have a destination frame and that the source container
  760.         // isn't the destination container
  761.         ASSERT(cloneInfo->fScopeFrame == NULL || cloneInfo->fScopeFrame->GetID(ev) == 
  762.                         fContainingFrameID, kODErrInvalidParameter);
  763.  
  764.         ODStorageUnitID frameID;
  765.         frameID = cloneInfo->fFromDraft->Clone(ev, cloneInfo->fKey, fFrameID, 0, fFrameID);
  766.                   
  767.          storage->GetStrongStorageUnitRef(ev, frameID, aSURef);
  768.     }
  769.     else
  770.     {
  771.         // Its not a clone
  772.          storage->GetStrongStorageUnitRef(ev, fFrameID, aSURef);
  773.     }
  774.     
  775.     // ----- Write out the embedded frame reference -----
  776.      StorageUnitSetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
  777. }
  778.  
  779. //------------------------------------------------------------------------------
  780. // Method:        Purge
  781. //
  782. // Description:    This method simply nulls the fFrame field after removing the frame
  783. // from the Editor's list. The frame itself should have already been completely
  784. // released before this method is called.
  785. //
  786. //------------------------------------------------------------------------------
  787. void CEmbeddedFrameProxy::Purge(Environment* ev)
  788. {
  789.     if (this->IsFrameInMemory())
  790.     {
  791.         // Remove from list of embedded frames
  792.         ODFrame* tFrame = CFrameProxy::GetFrame(ev);
  793.         fDrawEditor->GetEmbeddedFrames()->Remove(tFrame);
  794.         
  795.         // Eliminate our reference
  796.         this->SetFrame(kODNULL);
  797.     }
  798. }
  799.  
  800.  
  801. //------------------------------------------------------------------------------
  802. // Method:        CloseAndPurge
  803. //
  804. // Description:    This method calls frame::close on fFrame, then calls purge.
  805. //
  806. //------------------------------------------------------------------------------
  807. void CEmbeddedFrameProxy::CloseAndPurge(Environment* ev)
  808. {
  809.     if (this->IsFrameInMemory())
  810.     {
  811.         ODFrame* tFrame = CFrameProxy::GetFrame(ev);
  812.                 
  813.         #ifdef ODDebug
  814.             // Useful debugging information
  815.         
  816.             // The IsInLimbo call will throw if the frame has already
  817.             // been removed. We should assume false in this case.
  818.             ODBoolean isInLimbo = kODFalse;
  819.             TRY
  820.                 isInLimbo = tFrame->IsInLimbo(ev);
  821.             CATCH_ALL
  822.                 isInLimbo = kODFalse;
  823.             ENDTRY
  824.         
  825.             ODULong tRef = fFrame->GetRefCount(ev);
  826.         #endif
  827.         
  828.         tFrame->Close(ev);
  829.             
  830.         this->Purge(ev);
  831.     }
  832. }
  833.  
  834.  
  835. //------------------------------------------------------------------------------
  836. // Method:        RemoveAndPurge
  837. //
  838. // Description:    This method calls frame::remove on fFrame, then calls purge.
  839. //
  840. //------------------------------------------------------------------------------
  841. void CEmbeddedFrameProxy::RemoveAndPurge(Environment* ev)
  842. {
  843.     if (this->IsFrameInMemory())
  844.     {
  845.         ODFrame* tFrame = CFrameProxy::GetFrame(ev);
  846.         
  847.         // The IsInLimbo call will throw if the frame has already
  848.         // been removed. We should assume false in this case.
  849.         ODBoolean isInLimbo = kODFalse;
  850.         TRY
  851.             isInLimbo = tFrame->IsInLimbo(ev);
  852.         CATCH_ALL
  853.             isInLimbo = kODFalse;
  854.         ENDTRY
  855.         
  856.         #ifdef ODDebug
  857.             ODULong tRef = fFrame->GetRefCount(ev);
  858.         #endif
  859.     
  860.         if (isInLimbo)
  861.         {
  862.             tFrame->Remove(ev);
  863.         }
  864.         else
  865.             tFrame->Release(ev);
  866.             
  867.         this->Purge(ev);
  868.     }
  869. }
  870.  
  871.  
  872. //------------------------------------------------------------------------------
  873. // Method:        FindNextSequence
  874. //
  875. // Description:    
  876. //
  877. //------------------------------------------------------------------------------
  878. ODULong CEmbeddedFrameProxy::FindNextSequence(Environment* ev, ODULong group)
  879. {
  880.     ODULong sequenceCount = 0L;
  881.     
  882.     // Iterate over sibling embedded frames to find the current number of 
  883.     // frames in the base frame's group
  884.     COrdListIterator embeddedFrames(fDrawEditor->GetEmbeddedFrames());
  885.     
  886.     for (ODFrame* embeddedFrame = (ODFrame*)embeddedFrames.First(); 
  887.             embeddedFrames.IsNotComplete();
  888.             embeddedFrame = (ODFrame*)embeddedFrames.Next())
  889.     {
  890.         if (group == embeddedFrame->GetFrameGroup(ev))
  891.         {
  892.             // Don't assume the frame hasn't been created yet,
  893.             // only tally those frames with sequences assigned.
  894.             if (embeddedFrame->GetSequenceNumber(ev))
  895.                 sequenceCount++;
  896.         }
  897.     }
  898.     return sequenceCount;
  899. }
  900.  
  901. //------------------------------------------------------------------------------
  902. // Method:        RenumberFrameSequences
  903. //
  904. // Description:    This method will resequence all frames starting with the given 
  905. // sequence until the end of the sequence. In the case of ADD this method should 
  906. // be called BEFORE the new frame is given a sequence number. Likewise, in the 
  907. // case of REMOVE, the frame should have its sequence set to zero BEFORE calling 
  908. // renumber. Pass true to ADD a sequence or FALSE to remove a sequence. 
  909. //
  910. //------------------------------------------------------------------------------
  911. void CEmbeddedFrameProxy::RenumberFrameSequences(Environment* ev, ODULong sequence, ODBoolean addOrRemove)
  912. {
  913.     // Don't assume the frames are sequenced in the order of the OrderedList
  914.     // Find all frames in the specified range
  915.     COrderedList tCollection;
  916.     ODFrame* embeddedFrame = kODNULL;
  917.     
  918.     // Iterate over the embedded frames
  919.     COrdListIterator embeddedFrames(fDrawEditor->GetEmbeddedFrames());
  920.     for (embeddedFrame = (ODFrame*)embeddedFrames.First(); 
  921.             embeddedFrames.IsNotComplete();
  922.             embeddedFrame = (ODFrame*)embeddedFrames.Next())
  923.     {
  924.         if (embeddedFrame->GetSequenceNumber(ev)>=sequence)
  925.             tCollection.AddLast(embeddedFrame);
  926.     }
  927.     
  928.     // Renumber
  929.     COrdListIterator savedFrames(&tCollection);
  930.     for (embeddedFrame = (ODFrame*)savedFrames.First(); 
  931.             savedFrames.IsNotComplete();
  932.             embeddedFrame = (ODFrame*)savedFrames.Next())
  933.     {
  934.         ODULong tSequence = embeddedFrame->GetSequenceNumber(ev);
  935.         
  936.         if (addOrRemove)
  937.         {
  938.             embeddedFrame->ChangeSequenceNumber(ev, tSequence+1);
  939.         }
  940.         else
  941.         {
  942.             embeddedFrame->ChangeSequenceNumber(ev, tSequence-1);
  943.         }    
  944.     }
  945. }
  946.  
  947.  
  948. //------------------------------------------------------------------------------
  949. // Method:        IsInLimbo
  950. //
  951. // Description:    
  952. //
  953. //------------------------------------------------------------------------------
  954. ODBoolean CEmbeddedFrameProxy::IsInLimbo(Environment* ev) const
  955. {
  956.     if (this->IsFrameInMemory())
  957.     {
  958.         ODBoolean limbo = kODFalse;
  959.         TRY
  960.         limbo = fFrame->IsInLimbo(ev);
  961.         CATCH_ALL
  962.         ENDTRY
  963.         return limbo;        
  964.     }
  965.     else
  966.         // Assume that the frame is still in the document even though
  967.         // it has not been internalized yet. 
  968.         return kODFalse;
  969. }
  970.  
  971.  
  972. //------------------------------------------------------------------------------
  973. // Method:        SetInLimbo
  974. //
  975. // Description:    
  976. //
  977. //------------------------------------------------------------------------------
  978. void CEmbeddedFrameProxy::SetInLimbo(Environment* ev, ODBoolean isInLimbo)
  979. {
  980.     if (this->IsFrameInMemory())
  981.     {
  982.         #ifdef ODDebug
  983.             ODULong tRef = fFrame->GetRefCount(ev);
  984.         #endif
  985.     
  986.         fFrame->SetInLimbo(ev, isInLimbo);
  987.     }
  988. }
  989.  
  990.  
  991. //------------------------------------------------------------------------------
  992. // Method:        IsAttached
  993. //
  994. // Description:    
  995. //
  996. //------------------------------------------------------------------------------
  997. ODBoolean CEmbeddedFrameProxy::IsAttached(Environment* ev) const
  998. {
  999.     return fAttached;
  1000. }
  1001.  
  1002.  
  1003. //------------------------------------------------------------------------------
  1004. // Method:        Attach
  1005. //
  1006. // Description:    
  1007. //
  1008. //------------------------------------------------------------------------------
  1009. void CEmbeddedFrameProxy::Attach(Environment* ev)
  1010. {
  1011.     // Do not allow attaching more than once
  1012.     // as this will cause too manyfacets to be added
  1013.     // and subsequent update problems which are hard to track
  1014.     if (fAttached)
  1015.     {
  1016.         DebugStr("\pAlready attached!!");
  1017.     }
  1018.     
  1019.     // ----- Assume we will succeed -----
  1020.     fAttached = TRUE;
  1021.     
  1022.     ODFrame* tContainingFrame = kODNULL;
  1023.     ODFrame* containingFrame = this->AcquireContainingFrame(ev);
  1024.     ODFrame* frame = kODNULL;
  1025.     THROW_IF_NULL(containingFrame);
  1026.  
  1027.     TRY    
  1028.         // This causes the frame to be loaded, if it isn't
  1029.         frame = GetFrame(ev);
  1030.         THROW_IF_NULL(frame);
  1031.     
  1032.         // ----- Set the containing frame -----
  1033.         ODFrame* tContainingFrame = frame->AcquireContainingFrame(ev);
  1034.         if (tContainingFrame != containingFrame)
  1035.             frame->SetContainingFrame(ev, containingFrame);
  1036.         
  1037.         // Release acquired frame, though it is more likely that it will
  1038.         // be null since we will normally attach an unattached frame
  1039.         // so there will be no containing frame
  1040.         ODReleaseObject(ev, tContainingFrame);
  1041.     
  1042.     CATCH_ALL
  1043.         // Release acquired frame
  1044.         ODSafeReleaseObject(tContainingFrame);
  1045.         
  1046.         // Failed
  1047.         fAttached = kODFalse;
  1048.     ENDTRY
  1049.     
  1050.     // If the frame is in memory, and has a frame group and the
  1051.     // sequence is zero, then give it a valid sequence number ( iterate over frames )
  1052.     if (frame)
  1053.     {
  1054.         ODULong tGroup = frame->GetFrameGroup(ev);
  1055.         // If this frame is a part of a group
  1056.         if (tGroup!=0L)
  1057.         {
  1058.             // If this frame WAS a part of a sequence
  1059.             // Put it back there and renumber
  1060.             if (fSavedFrameSequence!=0L)
  1061.             {
  1062.                 this->RenumberFrameSequences(ev, fSavedFrameSequence, kAddSequenceNumber);
  1063.             }
  1064.             else
  1065.             // Otherwise, Find new sequence number
  1066.             {
  1067.                 ODULong tSequence = this->FindNextSequence(ev, tGroup);
  1068.                 
  1069.                 // Shouldn't need to renumber here, since we are appending
  1070.             }
  1071.         }
  1072.     }
  1073.     
  1074.     // Create facets for this frame, must wait to do this until after
  1075.     // frame is attached to containing frame, or OpenDoc will crash.
  1076.     this->CreateFacets(ev);    
  1077.  
  1078.     // Release acquired frame
  1079.     ODReleaseObject(ev, containingFrame);
  1080. }
  1081.  
  1082.  
  1083. //------------------------------------------------------------------------------
  1084. // Method:        Detach
  1085. //
  1086. // Description:    
  1087. //
  1088. //------------------------------------------------------------------------------
  1089. void CEmbeddedFrameProxy::Detach(Environment* ev)
  1090. {
  1091.     // Throw if we are not attached
  1092.     ASSERT(fAttached, kODErrInvalidParameter);
  1093.  
  1094.     ODFrame* containingFrame = AcquireContainingFrame(ev);
  1095.     THROW_IF_NULL(containingFrame);
  1096.     
  1097.     ODFrame* tContainingFrame = kODNULL;
  1098.     ODFrame* frame = kODNULL;
  1099.     
  1100.     // Delete our facets, muist do this before frame is removed from
  1101.     // its container, or OpenDoc will crash
  1102.     this->RemoveFacets(ev);
  1103.     
  1104.     TRY    
  1105.         
  1106.         // This causes the frame to be loaded, if it isn't
  1107.         frame = this->GetFrame(ev);
  1108.         THROW_IF_NULL(frame);
  1109.     
  1110.         // ----- Set the containing frame to null -----
  1111.         tContainingFrame = frame->AcquireContainingFrame(ev);
  1112.         
  1113.         if (tContainingFrame == containingFrame)
  1114.             frame->SetContainingFrame(ev, NULL);
  1115.             
  1116.         // Release acquired frame
  1117.         ODReleaseObject(ev, tContainingFrame);
  1118.     
  1119.     CATCH_ALL
  1120.         // Release acquired frame
  1121.         ODSafeReleaseObject(tContainingFrame);
  1122.         
  1123.     ENDTRY
  1124.     
  1125.     // If the frame is in memory, and has a frame group 
  1126.     // make the sequence zero, and renumber
  1127.     if (frame)
  1128.     {
  1129.         // If this frame is a part of a group
  1130.         if (frame->GetFrameGroup(ev)!=0L)
  1131.         {
  1132.             ODULong tSequence = frame->GetSequenceNumber(ev);
  1133.             frame->ChangeSequenceNumber(ev, 0L);
  1134.             this->RenumberFrameSequences(ev, tSequence, kRemoveSequenceNumber);
  1135.         }
  1136.     }
  1137.     
  1138.     // Release acquired frame
  1139.     ODReleaseObject(ev, containingFrame);
  1140.     
  1141.     // ----- It is now detached -----
  1142.     fAttached = FALSE;
  1143. }
  1144.  
  1145.  
  1146. //----------------------------------------------------------------------------------------
  1147. //    CEmbeddedFrameProxy::CreateFacetsForContainer
  1148. //----------------------------------------------------------------------------------------
  1149.  
  1150. void CEmbeddedFrameProxy::CreateFacetsForContainer(Environment* ev, ODFacet* facet)
  1151. {
  1152.     ODRect frameBounds;
  1153.     fEmbeddingShape->GetBoundingBox(&frameBounds);
  1154.     ODFrame* tFrame = this->GetFrame(ev);
  1155.     
  1156.     ODTransform* tTransform = kODNULL;
  1157.     
  1158.     TRY
  1159.         tTransform = tFrame->CreateTransform(ev);
  1160.         tTransform->SetOffset(ev, &frameBounds.TopLeft());
  1161.         
  1162.         ODFacet* embeddedFacet = facet->CreateEmbeddedFacet(ev,
  1163.                                                             tFrame,
  1164.                                                             kODNULL, 
  1165.                                                             tTransform,
  1166.                                                             kODNULL,
  1167.                                                             kODNULL,
  1168.                                                             kODNULL,
  1169.                                                             kODFrameInFront);
  1170.         
  1171.         embeddedFacet->SetSelected(ev, fEmbeddingShape->IsSelected());
  1172.     CATCH_ALL
  1173.         ODSafeReleaseObject(tTransform);
  1174.     ENDTRY
  1175.     
  1176.     ODReleaseObject(ev, tTransform);
  1177.     
  1178. }
  1179. //----------------------------------------------------------------------------------------
  1180. //    CEmbeddedFrameProxy::CreateFacets
  1181. //----------------------------------------------------------------------------------------
  1182.  
  1183. void CEmbeddedFrameProxy::CreateFacets(Environment* ev)
  1184. {
  1185.     ODFrame* containingFrame = AcquireContainingFrame(ev);
  1186.     THROW_IF_NULL(containingFrame);
  1187.     
  1188.     ODFrameFacetIterator* iter = kODNULL;
  1189.     ODVolatile(iter);
  1190.     
  1191.     TRY
  1192.         
  1193.         ODFrameFacetIterator* iter = containingFrame->CreateFacetIterator(ev);
  1194.         for (ODFacet* embeddingFacet = iter->First(ev); iter->IsNotComplete(ev); embeddingFacet = iter->Next(ev))
  1195.         {
  1196.             this->CreateFacetsForContainer(ev, embeddingFacet);
  1197.         }
  1198.         
  1199.         delete iter;
  1200.         
  1201.     CATCH_ALL
  1202.         if (iter)
  1203.             delete iter;
  1204.             
  1205.         #ifdef ODDebug
  1206.         DebugStr("\p Exception thrown creating facets!");
  1207.         #endif
  1208.     ENDTRY
  1209.     
  1210.     // Release acquired frame
  1211.     ODReleaseObject(ev, containingFrame);
  1212. }
  1213.  
  1214.  
  1215.  
  1216. //----------------------------------------------------------------------------------------
  1217. //    CEmbeddedFrameProxy::RemoveFacetsForContainerFacet
  1218. //----------------------------------------------------------------------------------------
  1219.  
  1220. void CEmbeddedFrameProxy::RemoveFacetsForContainer(Environment* ev, ODFacet* facet)
  1221. {
  1222.     COrderedList tCollection;
  1223.     
  1224.     ODFacetIterator* iter = kODNULL;
  1225.     ODVolatile(iter);
  1226.     
  1227.     TRY
  1228.         // Find all the embedded facets of the frame, then store them in a 
  1229.         // temp collection For later removal
  1230.         ODFacetIterator* iter = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  1231.         for (ODFacet* facet = iter->First(ev); iter->IsNotComplete(ev); facet = iter->Next(ev))
  1232.         {
  1233.             if (facet->GetFrame(ev) == this->GetFrame(ev))
  1234.                 tCollection.AddLast(facet);
  1235.         }
  1236.         
  1237.         // Now, remove the facets.
  1238.         COrdListIterator ite2(&tCollection);
  1239.         for (facet = (ODFacet*)ite2.First(); ite2.IsNotComplete(); facet = (ODFacet*)ite2.Next())
  1240.         {
  1241.             facet->GetContainingFacet(ev)->RemoveFacet(ev, facet);
  1242.             delete facet;
  1243.         }
  1244.     
  1245.         delete iter;
  1246.     
  1247.     CATCH_ALL
  1248.         if (iter)
  1249.             delete iter;
  1250.         DebugStr("\p Exception thrown removing facets!");
  1251.     ENDTRY
  1252. }
  1253.  
  1254. //----------------------------------------------------------------------------------------
  1255. //    CEmbeddedFrameProxy::RemoveFacets
  1256. //----------------------------------------------------------------------------------------
  1257.  
  1258. void CEmbeddedFrameProxy::RemoveFacets(Environment* ev)
  1259. {
  1260.     // If the frame isn't loaded then there are no facets
  1261.     if (!IsFrameInMemory())
  1262.         return;
  1263.         
  1264.     ODFrame* containingFrame = AcquireContainingFrame(ev);
  1265.     THROW_IF_NULL(containingFrame);
  1266.         
  1267.     ODFrameFacetIterator* iter = kODNULL;
  1268.     
  1269.     ODVolatile(iter);
  1270.     
  1271.     TRY
  1272.         ODFrameFacetIterator* iter = containingFrame->CreateFacetIterator(ev);
  1273.         for (ODFacet* embeddingFacet = iter->First(ev); iter->IsNotComplete(ev); embeddingFacet = iter->Next(ev))
  1274.         {
  1275.             this->RemoveFacetsForContainer(ev, embeddingFacet);
  1276.         }
  1277.         
  1278.         delete iter;
  1279.         
  1280.     CATCH_ALL
  1281.         if (iter)
  1282.             delete iter;
  1283.         DebugStr("\p Exception thrown removing facets!");
  1284.     ENDTRY
  1285.         
  1286.     // Release acquired frame
  1287.     ODReleaseObject(ev, containingFrame);
  1288.     
  1289. }
  1290.  
  1291.  
  1292. //------------------------------------------------------------------------------
  1293. // Method:        OffsetFrame
  1294. //
  1295. // Description:    
  1296. //
  1297. //------------------------------------------------------------------------------
  1298. void CEmbeddedFrameProxy::OffsetFrame(Environment* ev, ODPoint offset)
  1299. {
  1300.     ODFrame* frame = GetFrame(ev);
  1301.     THROW_IF_NULL(frame);
  1302.         
  1303.     // Should call RepositionFacets here instead of below code
  1304.     
  1305.     if (offset.x != 0 || offset.y!=0)
  1306.     {
  1307.         ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
  1308.         for (ODFacet* odFacet = iter->First(ev); iter->IsNotComplete(ev); odFacet = iter->Next(ev))
  1309.         {
  1310.             ODTransform* tTransform  = ODCopyAndRelease(ev, odFacet->AcquireExternalTransform(ev, kODNULL));            
  1311.                     
  1312.             tTransform->MoveBy(ev, &offset);
  1313.             odFacet->ChangeGeometry(ev, kODNULL, tTransform, kODNULL);
  1314.             
  1315.             // Release acquired geometry
  1316.             ODReleaseObject(ev, tTransform);
  1317.         }
  1318.     }
  1319. }
  1320.  
  1321.  
  1322.  
  1323.  
  1324. //----------------------------------------------------------------------------------------
  1325. //    CEmbeddedFrameProxy::ResizeFrame
  1326. //----------------------------------------------------------------------------------------
  1327.  
  1328. void CEmbeddedFrameProxy::ResizeFrame(Environment* ev, ODRect resizeRect)
  1329. {
  1330.     // If there is no frame to resize, then return
  1331.     if (!this->IsFrameInMemory())
  1332.         return;
  1333.         
  1334.     // Setup resize geometry
  1335.     ODFrame*    frame = GetFrame(ev);
  1336.     ODShape*    newShape = frame->CreateShape(ev);
  1337.     
  1338.     newShape->SetRectangle(ev, &resizeRect);
  1339.     
  1340.     // Make the shape zero based since ODFrames are.
  1341.     ODPoint offset(-resizeRect.left, -resizeRect.top);
  1342.     ODTransform* tTransform = frame->CreateTransform(ev);
  1343.     tTransform->MoveBy(ev, &offset);
  1344.     
  1345.     // The new shape is ready
  1346.     newShape->Transform(ev, tTransform);
  1347.     
  1348.     // Reposition the facets of the frame we just resized
  1349.     ODPoint topLeft(resizeRect.left, resizeRect.top);
  1350.     RePositionFrameFacets(ev, topLeft);
  1351.     
  1352.     frame->ChangeFrameShape(ev, newShape, NULL);
  1353.  
  1354.     // Release acquired geometry
  1355.     ODReleaseObject(ev, newShape);
  1356.     ODReleaseObject(ev, tTransform);
  1357. }
  1358.  
  1359.  
  1360. //----------------------------------------------------------------------------------------
  1361. //    CEmbeddedFrameProxy::RePositionFrameFacets
  1362. //----------------------------------------------------------------------------------------
  1363.  
  1364. void CEmbeddedFrameProxy::RePositionFrameFacets(Environment* ev, ODPoint& topLeft)
  1365. {
  1366.     ODFrame* frame = this->GetFrame(ev);
  1367.     
  1368.     ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);            
  1369.     for (ODFacet* odFacet = iter->First(ev); iter->IsNotComplete(ev); odFacet = iter->Next(ev))
  1370.     {
  1371.         ODTransform* tTransform = odFacet->AcquireExternalTransform(ev, NULL);            
  1372.         
  1373.         tTransform->Reset(ev);
  1374.         tTransform->MoveBy(ev, &topLeft);
  1375.         
  1376.         odFacet->ChangeGeometry(ev, NULL, tTransform, NULL);
  1377.         
  1378.         // Release acquired geometry
  1379.         ODReleaseObject(ev, tTransform);
  1380.     }
  1381. }
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.